# Copyright 2025 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:build_defs.oss.bzl", "iree_compiler_cc_library", "iree_gentbl_cc_library", "iree_tablegen_doc", "iree_td_library")
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

iree_td_library(
    name = "td_files",
    srcs = enforce_glob(
        [
            "TensorExtAttrs.td",
            "TensorExtBase.td",
            "TensorExtInterfaces.td",
            "TensorExtOps.td",
        ],
        include = ["*.td"],
    ),
    deps = [
        "//compiler/src/iree/compiler/Dialect/Util/IR:td_files",
        "//compiler/src/iree/compiler/Utils:td_files",
        "@llvm-project//mlir:BuiltinDialectTdFiles",
        "@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
    ],
)

iree_compiler_cc_library(
    name = "IR",
    srcs = [
        "TensorExtAttrInterfaces.cpp",
        "TensorExtAttrInterfaces.cpp.inc",
        "TensorExtAttrs.cpp",
        "TensorExtAttrs.cpp.inc",
        "TensorExtDialect.cpp",
        "TensorExtDialect.cpp.inc",
        "TensorExtOpFolders.cpp",
        "TensorExtOpInterfaces.cpp",
        "TensorExtOpInterfaces.cpp.inc",
        "TensorExtOps.cpp",
        "TensorExtOps.cpp.inc",
        "TensorExtTypes.cpp",
    ],
    hdrs = [
        "TensorExtAttrInterfaces.h",
        "TensorExtAttrInterfaces.h.inc",
        "TensorExtAttrs.h",
        "TensorExtAttrs.h.inc",
        "TensorExtDialect.h",
        "TensorExtDialect.h.inc",
        "TensorExtOpInterfaces.h",
        "TensorExtOpInterfaces.h.inc",
        "TensorExtOps.h",
        "TensorExtOps.h.inc",
        "TensorExtTypes.h",
    ],
    deps = [
        ":TensorExtAttrInterfacesGen",
        ":TensorExtAttrsGen",
        ":TensorExtOpInterfacesGen",
        ":TensorExtOpsGen",
        "//compiler/src/iree/compiler/Dialect/Util/IR",
        "//compiler/src/iree/compiler/Utils",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:ArithUtils",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:InliningUtils",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
    ],
)

iree_gentbl_cc_library(
    name = "TensorExtAttrsGen",
    tbl_outs = [
        (
            [
                "--dialect=iree_tensor_ext",
                "--gen-attrdef-decls",
            ],
            "TensorExtAttrs.h.inc",
        ),
        (
            [
                "--dialect=iree_tensor_ext",
                "--gen-attrdef-defs",
            ],
            "TensorExtAttrs.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "TensorExtAttrs.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "TensorExtAttrInterfacesGen",
    tbl_outs = [
        (
            ["--gen-attr-interface-decls"],
            "TensorExtAttrInterfaces.h.inc",
        ),
        (
            ["--gen-attr-interface-defs"],
            "TensorExtAttrInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "TensorExtInterfaces.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "TensorExtOpInterfacesGen",
    tbl_outs = [
        (
            ["--gen-op-interface-decls"],
            "TensorExtOpInterfaces.h.inc",
        ),
        (
            ["--gen-op-interface-defs"],
            "TensorExtOpInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "TensorExtInterfaces.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "TensorExtOpsGen",
    tbl_outs = [
        (
            ["--gen-op-decls"],
            "TensorExtOps.h.inc",
        ),
        (
            ["--gen-op-defs"],
            "TensorExtOps.cpp.inc",
        ),
        (
            [
                "--dialect=iree_tensor_ext",
                "--gen-dialect-decls",
            ],
            "TensorExtDialect.h.inc",
        ),
        (
            [
                "--dialect=iree_tensor_ext",
                "--gen-dialect-defs",
            ],
            "TensorExtDialect.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "TensorExtOps.td",
    deps = [":td_files"],
)

iree_tablegen_doc(
    name = "TensorExtDialectDocGen",
    category = "Dialects",
    tbl_outs = [
        (
            [
                "--gen-dialect-doc",
                "-dialect=iree_tensor_ext",
            ],
            "TensorExtDialect.md",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "TensorExtOps.td",
    deps = [":td_files"],
)
